package reflect;

import reflect.annotations.AutoRunClass;
import reflect.annotations.AutoRunMethod;

import java.lang.reflect.Method;

public class test3 {
    public static void main(String[] args) throws Exception{
        Class cls=Class.forName("reflect.Person");
        Object o = cls.newInstance();

        if (cls.isAnnotationPresent(AutoRunClass.class)){
            Method[] methods = cls.getMethods();
            for (Method method: methods){
                if (method.isAnnotationPresent(AutoRunMethod.class)){
                    AutoRunMethod annotation = method.getAnnotation(AutoRunMethod.class);
                    int value = annotation.value();
                    System.out.println("value值是"+value);
                    for (int i=0;i<value;i++){
                        method.invoke(o);
                    }
                }else {
                    System.out.println(method.getName()+"方法没有被标注");
                }
            }
        }else{
            System.out.println(cls.getSimpleName()+"类没有被标注！");
        }

    }
}
